package protocol.SZ_2021;

import java.util.HashMap;

public class Handle2021SZ08 implements IHandle2021SZ {
    @Override
    public String handle(SZ_2021Cmd cmd) {
        byte subOrder = cmd.subOrder();

        switch (subOrder){
            case 0x00:
                return handle0800(cmd);
            case 0x02:
                return handle0802(cmd);
            default:
                return "深标:未匹配的命令字"+(cmd.readOrder()+","+cmd.readSubOrder());
        }
    }

    private String handle0802(SZ_2021Cmd cmd) {
        StringBuilder builder = new StringBuilder();
        builder.append("终端->平台:存储图像检索应答");
        builder.append("\r\n");
        builder.append("应答流水号:"+cmd.readInt(2));
        builder.append("\r\n");
        builder.append("检索总项数据包大小:"+cmd.readInt(4));
        builder.append("\r\n");
        builder.append("当前检索项在总项数据中的偏移量:"+cmd.readInt(4));
        builder.append("\r\n");
        builder.append("检索项:"+cmd.readBCD(cmd.leftSize()));
        builder.append("\r\n");

        return builder.toString();
    }

    private String handle0800(SZ_2021Cmd cmd) {
        StringBuilder builder = new StringBuilder();
        builder.append("终端->平台:摄像头图像上传");
        builder.append("\r\n");
        builder.append("上传原因/流水号:"+cmd.readInt(2));
        builder.append("\r\n");
        builder.append("图像ID:"+cmd.readInt(4));
        builder.append("\r\n");
        builder.append("摄像头ID:"+cmd.readInt(1));
        builder.append("\r\n");
        builder.append("位置图像数据大小:"+cmd.readInt(4));
        builder.append("\r\n");
        builder.append("偏移量:"+cmd.readInt(4));
        builder.append("\r\n");
        builder.append("图像数据:");
        builder.append("\r\n");
        builder.append("    终端ID号:"+cmd.readBCD(5));
        builder.append("\r\n");
        builder.append("    编码方式:"+cmd.readBCD(1));
        builder.append("\r\n");
        builder.append("    车牌号:"+cmd.readString(10));
        builder.append("\r\n");
        builder.append("    营运ID:"+cmd.readInt(4));
        builder.append("\r\n");

        HashMap<Integer,String> list = new HashMap<>();
        list.put(0,"进入重车拍照");
        list.put(1,"服务评价拍照");
        list.put(2,"报警拍照");
        list.put(3,"中心主动拍照");
        list.put(4,"车辆点火");
        list.put(5,"司机签到");
        list.put(6,"司机签退");
        list.put(7,"重翻空");
        list.put(8,"司机照片");
        list.put(9,"车门开关");
        list.put(10,"固定间隔自动拍照");
        list.put(11,"紧急预警");
        list.put(12,"超速报警");
        list.put(13,"出城登记");
        list.put(14,"违规运营（不打表营运）");
        list.put(15,"人脸识别拍照（刷脸签到）");
        list.put(16,"SD 卡拔出拍照");
        list.put(17," 终端卡盖开启拍照");
        list.put(18,"GPS 天线故障拍照");
        list.put(19,"动态查岗拍照（动态查岗）");
        list.put(20,"DSM 重度疲劳驾驶报警");
        list.put(21,"DSM 打电话报警");
        list.put(22,"DSM 抽烟报警");
        list.put(23,"DSM 分心驾驶报警");
        list.put(24,"DSM 异常驾驶报警");
        list.put(25,"司机不系安全带报警");
        list.put(26,"乘客不系安全带报警");
        list.put(31,"乘客人脸抓拍照片");
        list.put(32,"客流统计拍照");
        list.put(33,"车牌照片");
        list.put(34,"违章抓拍");
        list.put(35,"急加速报警");
        list.put(36,"急减速报警");
        list.put(37,"暴力驾驶报警");
        list.put(38,"PCW 报警");
        list.put(39,"FCW 报警");
        list.put(40,"LDW 报警");
        list.put(41,"脏话报警");
        list.put(42,"危险语音报警");
        list.put(43,"DSM 轻度疲劳（打哈欠）");
        list.put(44,"运维安装抓拍");
        list.put(45,"视频丢失报警");
        list.put(46,"司机未戴口罩");
        list.put(47,"乘客未戴口罩");

        builder.append("    拍照原因："+list.getOrDefault(cmd.readInt(1),"未定义"));
        builder.append("\r\n");
        builder.append("    拍照时间:"+cmd.readBCD(6));
        builder.append("\r\n");
        builder.append("    拍照地点的纬度(1/10000分):"+cmd.readInt(4));
        builder.append("\r\n");
        builder.append("    拍照地点的经度(1/10000分):"+cmd.readInt(4));
        builder.append("\r\n");
        builder.append("    照片文件ID号:"+cmd.readInt(4));
        builder.append("\r\n");
        builder.append("    图像数据的大小:"+cmd.readInt(4));
        builder.append("\r\n");

        cmd.moveIndex(127-43);
        builder.append("    图像数据："+cmd.readBCD(cmd.leftSize()));

        return builder.toString();
    }
}
